package com.example.mic;

import com.example.preference.UserPreference;
import com.example.voicedet.R;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;



/*** 
 * @author tr
 * @time 2014-2-17
 * @description 大悬浮窗对象类 */
public class FloatWindowBigView extends LinearLayout{

	private UserPreference mUserPreference;
	/**记录大悬浮窗的宽度*/
	public static int viewWidth;
	/**记录大悬浮窗的高度*/
	public static int viewHeight;
	
	private ImageView  volume;
	
	public FloatWindowBigView(final Context context,double signalEMA) {
		super(context);
		// TODO Auto-generated constructor stub
		LayoutInflater.from(context).inflate(R.layout.floatwindowbig, this);
		View view = findViewById(R.id.bigwindowlayout);
		viewWidth = view.getLayoutParams().width;
		viewHeight = view.getLayoutParams().height;
		Button close = (Button) findViewById(R.id.close);
		
		
		volume = (ImageView) this.findViewById(R.id.volume);
		
		mUserPreference = new UserPreference(context);
		//关闭按钮   监听
		close.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Log.d("Window_Set",context.toString());
				
				mUserPreference.putBoolean(UserPreference.KEY_CANCEL_BUG, true);
				
				BigWindow.removeBigWindow(context);
			}
		});

	}
	
	
	public void updateDisplay(double signalEMA) {
		
		switch ((int) signalEMA) {
		case 0:
		case 1:
			volume.setImageResource(R.drawable.amp1);
			break;
		case 2:
		case 3:
			volume.setImageResource(R.drawable.amp2);
			break;
		case 4:
		case 5:
			volume.setImageResource(R.drawable.amp3);
			break;
		case 6:
		case 7:
			volume.setImageResource(R.drawable.amp4);
			break;
		case 8:
		case 9:
			volume.setImageResource(R.drawable.amp5);
			break;
		case 10:
		case 11:
			volume.setImageResource(R.drawable.amp6);
			break;
		default:
			volume.setImageResource(R.drawable.amp7);
			break;
		}
	}
	
}
